package com.aixin.project.servlet;

import com.aixin.project.data.Fee;
import com.aixin.project.data.User;
import com.aixin.project.db.FeeDao;
import com.aixin.project.handler.UserHandler;
import org.apache.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.ServletUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 12-4-9
 * Time: 上午1:37
 * To change this template use File | Settings | File Templates.
 */
public class DemoServlet extends BaseServlet {
    Logger logger = Logger.getLogger(DemoServlet.class);
    @Override
    protected Template execute(HttpServletRequest request, HttpServletResponse response, Context ctx) {
        Fee fee = new Fee();
        fee.setType(0);
        fee.setFee(500.00);
        fee.setOrderid(1);
        fee.setUserid(1);
        long fid = FeeDao.create(fee);
        System.out.println("fid:"+fid);

        User user = new User(); user.setUsername("sufeng"); user.setPassword("password");
        long id = UserHandler.insert(user);
        User userOne = UserHandler.find(1);
        List<User> users = UserHandler.getAllUsers();

        ctx.put("user",userOne);
        ctx.put("users",users);
        ctx.put("name","sufengster");
        ctx.put("result",id);
        logger.info("[User.size]"+users.size());
        return getTemplate("demo.vm");
    }
}

